package org.microframework.cloud.logs.controller;

import org.microframework.base.core.domain.R;
import org.microframework.base.core.web.controller.BaseController;
import org.microframework.base.core.web.page.PageQuery;
import org.microframework.cloud.logs.model.domain.LoginLog;
import org.microframework.cloud.logs.model.dto.LoginLogDTO;
import org.microframework.cloud.logs.service.ILoginLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.jfinal.plugin.activerecord.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * 登录日志控制器
 *
 * @author zs
 * @version 1.0.0
 * @since 2024-06-14
 */
@RestController
@RequestMapping("/loginLog")
@Tag(name = "登录日志", description = "登录日志管理接口")
public class LoginLogController extends BaseController {

    @Autowired
    private ILoginLogService loginLogService;

    /**
     * 查询登录日志列表
     */
    @GetMapping("/pages")
    @Operation(summary = "查询登录日志列表", description = "分页查询登录日志数据")
    public R<Page<LoginLogDTO>> pages(PageQuery<LoginLog> pageQuery) {
        return R.ok(loginLogService.selectLoginLogList(pageQuery));
    }

    /**
     * 获取登录日志详细信息
     */
    @GetMapping("/{id}")
    @Operation(summary = "获取登录日志详情", description = "根据ID查询登录日志详情")
    public R<LoginLogDTO> getInfo(@Parameter(description = "日志ID") @PathVariable("id") String id) {
        return R.ok(loginLogService.selectLoginLogById(id));
    }

    /**
     * 删除登录日志
     */
    @DeleteMapping("/{ids}")
    @Operation(summary = "删除登录日志", description = "根据ID批量删除登录日志")
    public R<Integer> remove(@Parameter(description = "日志ID，多个以逗号分隔") @PathVariable String ids) {
        return R.ok(loginLogService.deleteLoginLogByIds(ids));
    }

    /**
     * 清空登录日志
     */
    @DeleteMapping("/clean")
    @Operation(summary = "清空登录日志", description = "清空所有登录日志")
    public R<Boolean> clean() {
        return R.ok(loginLogService.cleanLoginLog());
    }

    /**
     * 导出登录日志
     */
    @PostMapping("/export")
    @Operation(summary = "导出登录日志", description = "导出登录日志数据")
    public R<Object> export(LoginLogDTO queryDTO) {
        return R.ok(loginLogService.exportLoginLog(queryDTO));
    }
} 